<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top:10px;
  }
  .employee-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
  .btn-export {
    float: left;
  }
  .btn-upload {
    float: left;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>人事管理员工信息</span>
    </div>
    <div class="line"></div>
    <employee-form
      @on-success-valid="handleSubmit"
      class="employee-form">
    </employee-form>
    <Button
      icon="md-add"
      type="primary"
      @click="handleClick">
      添加
    </Button>
    <!-- <btn-export :tableData="employeeList" :tableTitle="columns" :title="title" class="btn-export"></btn-export> -->
    <!-- <btn-upload class="btn-upload" :title="title"></btn-upload> -->
    <employee-modal
      @employee-valid="handleEdit">
    </employee-modal>
    <Table
      :columns="columns"
      :data="historyData"
      border
      class="table">
    </Table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import EmployeeForm from '_c/employee-form'
import EmployeeModal from '_c/employee-modal'
import TablePage from '_c/page'
import BtnExport from '_c/btn-export'
import BtnUpload from '_c/btn-upload'
export default {
  components: {
    EmployeeForm,
    EmployeeModal,
    TablePage,
    BtnExport,
    BtnUpload
  },
  data () {
    return {
      page: 1,
      title: '人事管理员工信息',
      columns: [
        {
          title: '序号',
          type: 'index2',
          width: 65,
          align: 'center',
          fixed: 'left',
          render: (h, params) => {
            return h('span', params.index + (this.page - 1) * this.pageSize + 1)
          }
        },
        {
          title: '姓名',
          key: 'name',
          width: 100,
          align: 'center',
          fixed: 'left'
        },
        {
          title: '性别',
          key: 'sex',
          width: 100,
          align: 'center'
        },
        {
          title: '年龄',
          key: 'age',
          width: 100,
          align: 'center'
        },
        {
          title: '联系电话',
          key: 'tel',
          width: 120,
          align: 'center'
        },
        {
          title: '出生年月',
          key: 'birthmonth',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.birthmonth ? params.row.birthmonth : '-'
            )
          }
        },
        {
          title: '生日日期',
          key: 'birthday',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.birthday ? this.$moment(params.row.birthday).format('YYYY-MM-DD') : '-'
            )
          }
        },
        // {
        //   title: '生日提醒',
        //   key: 'birthmind',
        //   width: 100,
        //   align: 'center',
        //   render: (h, params) => {
        //     return h(
        //       'span',
        //       {},
        //       params.row.birthmind ? this.$moment(params.row.birthmind).format('YYYY-MM-DD') : '-'
        //     )
        //   }
        // },
        {
          title: '身份证号',
          key: 'idcard',
          width: 200,
          align: 'center'
        },
        {
          title: '民族',
          key: 'people',
          width: 100,
          align: 'center'
        },
        {
          title: '婚姻状况',
          key: 'marriage',
          width: 100,
          align: 'center'
        },
        {
          title: '紧急联系人',
          key: 'emergency',
          width: 100,
          align: 'center'
        },
        {
          title: '关系',
          key: 'rel',
          width: 100,
          align: 'center'
        },
        {
          title: '紧急联系方式',
          key: 'etel',
          width: 120,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.etel ? params.row.etel : '-'
            )
          }
        },
        {
          title: '毕业学校',
          key: 'school',
          width: 120,
          align: 'center'
        },
        {
          title: '学历',
          key: 'ab',
          width: 100,
          align: 'center'
        },
        {
          title: '学历补充说明',
          key: 'abcommit',
          width: 150,
          align: 'center'
        },
        {
          title: '专业',
          key: 'study',
          width: 100,
          align: 'center'
        },
        {
          title: '政治面貌',
          key: 'selfposition',
          width: 100,
          align: 'center'
        },
        {
          title: '籍贯',
          key: 'native',
          width: 100,
          align: 'center'
        },
        {
          title: '现居住地址',
          key: 'residence',
          width: 300,
          align: 'center'
        },
        {
          title: '户籍地址',
          key: 'nativeres',
          width: 300,
          align: 'center'
        },
        {
          title: '户籍类型',
          key: 'householdtype',
          width: 100,
          align: 'center'
        },
        {
          title: '年假申请时间',
          key: 'annualtime',
          width: 130,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.annualtime ? this.$moment(params.row.annualtime).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '银行名称',
          key: 'bankname',
          width: 100,
          align: 'center'
        },
        {
          title: '支行名称',
          key: 'subbank',
          width: 130,
          align: 'center'
        },
        {
          title: '银行卡所在省',
          key: 'bankprovince',
          width: 130,
          align: 'center'
        },
        {
          title: '银行卡所在市',
          key: 'bankcity',
          width: 130,
          align: 'center'
        },
        {
          title: '银行卡号',
          key: 'bankcard',
          width: 200,
          align: 'center'
        },
        {
          title: '银行卡号',
          key: 'backcard',
          width: 200,
          align: 'center'
        },
        {
          title: '社保',
          key: 'ssn',
          width: 100,
          align: 'center'
        },
        {
          title: '公积金',
          key: 'publicfund',
          width: 100,
          align: 'center'
        },
        {
          title: '工号',
          key: 'num',
          width: 100,
          align: 'center'
        },
        {
          title: '部门名称',
          key: 'deptname',
          width: 100,
          align: 'center'
        },
        {
          title: '司龄',
          key: 'coage',
          width: 100,
          align: 'center'
        },
        {
          title: '工作岗位',
          key: 'job',
          width: 100,
          align: 'center'
        },
        {
          title: '工牌颜色',
          key: 'color',
          width: 100,
          align: 'center'
        },
        {
          title: '劳动合同',
          key: 'contract',
          width: 100,
          align: 'center'
        },
        {
          title: '合同到期日',
          key: 'expiredday',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.expiredday ? this.$moment(params.row.expiredday).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '合同起始日',
          key: 'contractstart',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.contractstart ? this.$moment(params.row.contractstart).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '合同结束日',
          key: 'contractend',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.contractend ? this.$moment(params.row.contractend).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '试用期时长(月)',
          key: 'probation',
          width: 120,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.probation ? params.row.probation : '-'
            )
          }
        },
        // {
        //   title: '试用期提醒',
        //   key: 'probationmind',
        //   width: 100,
        //   align: 'center',
        //   render: (h, params) => {
        //     return h(
        //       'span',
        //       {},
        //       params.row.probationmind ? this.$moment(params.row.probationmind).format('YYYY-MM-DD') : '-'
        //     )
        //   }
        // },
        {
          title: '实际转正日期',
          key: 'fullday',
          width: 130,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.fullday ? this.$moment(params.row.fullday).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '社保缴纳日期',
          key: 'sitime',
          width: 130,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.sitime ? this.$moment(params.row.sitime).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '入职时间',
          key: 'intime',
          width: 180,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.intime ? this.$moment(params.row.intime).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '离职时间',
          key: 'leavetime',
          width: 180,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.leavetime ? this.$moment(params.row.leavetime).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '状态',
          key: 'state',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.state === '0' ? '在职' : '离职'
            )
          }
        },
        {
          title: '备注',
          key: 'des',
          width: 200,
          align: 'center'
        },
        {
          title: '操作',
          key: 'cz',
          width: 250,
          fixed: 'right',
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small',
                  ghost: 'ghost'
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    this.handleClick(params.row.id, params.row)
                  }
                }
              }, '修改')
            ])
          }
        }
      ]
    }
  },
  computed: {
    ...mapState({
      employeeList: state => state.employee.employeeList,
      dataCount: state => state.employee.employeeDataCount,
      historyData: state => state.employee.employeeHistoryData,
      pageSize: state => state.employee.pageSize
    })
  },
  methods: {
    ...mapActions([
      'getEmployeesList',
      'getEmployeeCurrentRow',
      'editeEmployeeData',
      'updateModalState',
      'getDepartmentList',
      'changeEmployeePage',
      'getPidList'
    ]),
    handleSubmit (playload) {
      this.getEmployeesList(playload)
    },
    handleClick (id, row) {
      let newRow = {}
      this.id = id
      if (row) {
        newRow = Object.assign({}, row)
      }
      this.getEmployeeCurrentRow(newRow)
      this.updateModalState(true)
    },
    handleEdit (playload, id) {
      this.editeEmployeeData(playload).then(
        setTimeout(() => {
          this.getEmployeesList({ page: this.page })
        }, 100)
      )
      this.updateModalState(false)
    },
    changePage (index) {
      this.page = index
      this.changeEmployeePage(index)
      this.getEmployeesList({ page: index })
    }
  },
  created () {
    this.getEmployeesList({})
    this.getDepartmentList({})
    this.getPidList()
  }
}
</script>
